﻿namespace UsefulTools.ExtensionMethods
{
    using System;

    public static class Events
    {

        /// <summary>
        /// Invokes the action if it is not null.
        /// </summary>
        /// <param name="action"></param>
        public static void RaiseIfNotNull(this Action action )
        {
            if (action != null)
            {
                action();
            }
        }
        /// <summary>
        /// Invokes the action if it is not null.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="action"></param>
        /// <param name="p1"></param>
        public static void RaiseIfNotNull<T>(this Action<T> action, T p1)
        {
            if (action != null)
            {
                action(p1);
            }
        }
        /// <summary>
        /// Invokes the action if it is not null.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="action"></param>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public static void RaiseIfNotNull<T1, T2>(this Action<T1, T2> action, T1 p1, T2 p2)
        {
            if (action != null)
            {
                action(p1,p2);
            }
        }
        /// <summary>
        /// Invokes the action if it is not null.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <param name="action"></param>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        public static void RaiseIfNotNull<T1, T2, T3>(this Action<T1, T2, T3> action, T1 p1, T2 p2, T3 p3)
        {
            if (action != null)
            {
                action(p1, p2, p3);
            }
        }
    }
}